package com.niit;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserDao {

    private static final String url = "jdbc:mysql://localhost:3306/huel";
    private static final String username = "root";
    private static final String password = "123456";
    // JDBC 驱动名和数据库 URL
    // String driver = "com.mysql.jdbc.Driver";
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public List<User> query() {
        List<User> userList = new ArrayList<>();

        try (Connection conn = DriverManager.getConnection(url, username, password);
             PreparedStatement stmt = conn.prepareStatement("select * from student16")) {
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                String names= rs.getString("secl");
                int value1 = rs.getInt("sex");
                int value2 = rs.getInt("count");

                User user = new User(names,value1,value2);
                userList.add(user);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return userList;
    }
    }

